<template>
	<view>
		<view class="" v-for="(v,index) in item.store_info" :key="index">
			<view>
        <block v-for="(v_item, indey) in v" :key="indey">
        	<text v-if="indey == 0" class="flex u-p-y-10 font-weight-bold">{{v_item.merch_name}}</text>
					<view class="u-border-bottom">
						<order-item-list-good :item="v_item" @toOrderDetail="toOrderDetail"></order-item-list-good>
						<template v-if="item.showText == '待发货'">
							<view class="flex align-center justify-end text-center u-p-b-20">
								<dy-button width="140rpx" backgroundColor="#fff" color="#333" borderColor="#C2C5C8" v-if="v_item.is_weiquan == 0" @click="btnGood(v_item)">退款</dy-button>
								<dy-button width="140rpx" backgroundColor="#fff" color="#333" borderColor="#C2C5C8" disabled v-else-if ="v_item.is_weiquan == 2||v_item.is_weiquan == 3">维权完成</dy-button>
								<dy-button width="140rpx" backgroundColor="#fff" color="#333" borderColor="#C2C5C8" disabled v-else>维权中</dy-button>
							</view>
						</template>
						<template v-if="item.showText == '待收货'">
							<view class="flex align-center justify-end text-center u-p-b-20" v-if="item.is_cancel == 0">
								<dy-button width="140rpx" backgroundColor="#fff" color="#333" borderColor="#C2C5C8" v-if="v_item.is_weiquan == 0" @click="applyAfterGood(v_item)">申请售后</dy-button>
								<dy-button width="140rpx" backgroundColor="#fff" color="#333" borderColor="#C2C5C8" disabled v-else-if ="v_item.is_weiquan == 2||v_item.is_weiquan == 3">维权完成</dy-button>
								<dy-button width="140rpx" backgroundColor="#fff" color="#333" borderColor="#C2C5C8" disabled v-else>维权中</dy-button>
							</view>
						</template>
						<template v-if="item.showText == '待评价'">
							<view class="flex align-center justify-end text-center u-p-b-20">
								<dy-button width="140rpx" @click="btnAppraise(v_item)">晒单评价</dy-button>
							</view>
						</template>
					</view>
        </block>
			</view>
		</view>
    <order-item-waitpay v-if="item.showText == '待支付'" :item="item"></order-item-waitpay>
		<order-item-waitfreight v-if="item.showText == '待发货'" :item="item"></order-item-waitfreight>
		<order-item-waitreceipt v-if="item.showText == '待收货'" :item="item"></order-item-waitreceipt>
	</view>
</template>

<script>
	import { OrderCenterApi } from '@/api/serves.js'
	export default {
		name:"order-item-list",
		props: {
		  item: {
				type: Object,
				default() {
					return {}
				}
			}
		},
		data() {
			return {
				show: false
			}
		},
		mounted() {
			// console.log(2222, this.item);
		},
		methods: {
			// 取消支付
      cancleOrder() {
        uni.showModal({
          title: '提示',
          content: '确定取消订单吗?',
          success: (res)=> {
            if (res.confirm) {
              OrderCenterApi.cancel_order({ id: this.item.id }).then(res => {
              	this.$HideLoading()
                console.log('取消订单', res);
              	this.$Toast(res.msg)
              	if(res.code == 1){
              		uni.$emit('orderClick')
              	}
              })
            }
          }
        });
      },
			// 待发货单个商品退款
			btnGood(v_item) {
				uni.showModal({
					title: '提示',
					content: '确定申请退款吗?',
					success: (res)=> {
						if (res.confirm) {
							uni.showLoading()
							let params = {
								order_no: this.item.order_no, 
								goodsid: v_item.goods_id, 
								order_goods_id: v_item.id
							}
							OrderCenterApi.after_sale_goods1(params).then((res) => {
								this.$HideLoading()
								console.log('退款', res);
								this.$u.toast(res.msg)
								if(res.code == 1){
									uni.$emit('orderClick')
								}
							});
						}
					}
				});
			},
			// 待收货单个商品申请售后
			applyAfterGood(v) {
				let params = {
					type: 1,
					goods_id: v.goods_id,
					order_no: this.item.order_no,
				}
				// console.log('params', params);
				uni.navigateTo({
					url: '/pages/order/mineOrderAfterApply/mineOrderAfterApply?info=' + JSON.stringify(params)
				})
			},
			// 去评价
			btnAppraise(v) {
				let params = {
					order_id: this.item.id,
					images: v.images,
					goods_name: v.goods_name,
					goods_attr: v.goods_attr,
					goods_price: v.goods_price,
					total_num: v.total_num,
					goods_id: v.goods_id,
				}
				// console.log(params);
				uni.navigateTo({
					url: '/pages/order/mineOrderEvaluateAdd/mineOrderEvaluateAdd?info=' + JSON.stringify(params)
				})
			},
			toOrderDetail() {
				uni.navigateTo({
					url: '/pages/order/mineOrderDetail/mineOrderDetail?order_no=' + this.item.order_no
				})
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
